﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Pseudogenerator.Common.Generators;
using Pseudogenerator.Common.ViewModels.Core;

namespace Pseudogenerator.Common.ViewModels
{
    public class MitchellMooreViewModel
        : WorkSpaceViewModel<MitchellMoore>
    {

        public MitchellMooreViewModel()
        {
            ModeloActual = new MitchellMoore();
        }

        #region ModelFields


        public uint m
        {
            get
            {
                return ModeloActual.m;
            }
            set
            {
                if (ModeloActual.m == value)
                    return;
                ModeloActual.m = value;
                OnPropertyChanged();
                RefreshGUI();
            }
        }

        public uint n
        {
            get
            {
                return ModeloActual.n;
            }
            set
            {
                if (ModeloActual.n == value)
                    return;
                ModeloActual.n = value;
                OnPropertyChanged();
                RefreshGUI();
            }
        }

        #endregion

        public override string Title
        {
            get { return "Mitchell y Moore"; }
        }

        public override bool CanRun
        {
            get
            {
                return !InWorkProgress && ModeloActual.CanGenerateNext;
            }
        }

        private MitchellMoore _ModeloActual = null;
        public override MitchellMoore ModeloActual
        {
            get
            {
                if (_ModeloActual == null)
                    _ModeloActual = new MitchellMoore();

                return _ModeloActual;
            }
            set
            {
                if (value == null)
                    return;
                this.m = value.m;
                this.n = value.n;                
                ClearCommand.Execute(null);
            }
        }


        public override IEnumerable<string> Errors
        {
            get 
            { 
                if (n < 54)
                    yield return "'n' debe ser mayor que 54";
                if (m % 2 != 0)
                    yield return "'m' debe ser par";
            }
        }

        public override IEnumerable<string> Recommendations
        {
            get { return new List<string>(); }
        }

        protected override void AddPreload()
        {
            var actual = Preloads.FirstOrDefault(i => i.n == n && i.m == m);
            if (actual == null)
            {
                Preloads.Add(new MitchellMoore() { n = n, m = m });
            }
        }
    }
}
